package ch.zbw.sysventory.server.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import ch.zbw.sysventory.server.model.ComputerScan;
import ch.zbw.sysventory.server.service.ComputerScanResultService;
import ch.zbw.sysventory.server.service.ComputerScanService;

@Component
@Controller
public class OperatingSystemStatisticController {

	@Autowired
	private ComputerScanService computerScanService;

	@Autowired
	private ComputerScanResultService computerScanResultService;

	@RequestMapping(value = "/operatingsystemstatistic", method = RequestMethod.GET)
	public ModelAndView showSoftwareStatistic(Model model) {
		ComputerScan latestScan = this.computerScanService.getLatestScan();
		List<String> operatingSystemList = this.computerScanResultService.listAllOperatingSystemsForLatestScan(latestScan);
		model.addAttribute("amountInstalledOS", operatingSystemList.size());
		model.addAttribute("result_list", operatingSystemList);
		return new ModelAndView("operatingsystemstatistic");
	}

}
